<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>Hui</title>
    <link href="../../css/Hui.css" rel="stylesheet" type="text/css" />
    <style type="text/css"></style>
</head>
<body>
	
	<div class="H-padding-vertical-bottom-10"></div>
	<header class="H-header H-theme-background-color9 H-padding-vertical-top-25" id="header">
	    <span onclick="goBack()" class="H-icon H-position-relative H-display-inline-block H-float-left H-vertical-middle H-theme-font-color-white H-padding-horizontal-left-5 H-z-index-100">
			<i class="H-iconfont H-icon-target-back H-font-size-18 H-vertical-middle"></i>
		</span>
	    <div class="H-header-title H-center-all H-font-size-18 H-text-show-row-1 H-theme-font-color-white 
		H-position-absolute H-width-100-percent">我的</div>
	</header>
 
    <div class="H-padding-vertical-bottom-10"></div>
    <!--################### 单行，带文字图标，带缩进线 ###################-->
    <div class="H-channel-title H-flexbox-horizontal H-theme-background-color-white H-vertical-middle H-border-vertical-bottom-after">
        <div class="H-channel-line H-theme-background-color-black H-padding-vertical-top-15 H-padding-horizontal-left-3  H-margin-horizontal-left-10"></div>
        <div class="H-channel-text H-theme-font-color-black H-flex-item
        H-font-size-18 H-theme-font-color-black H-padding-10 H-margin-horizontal-right-10 H-text-show-row-1">修改密码</div>
    </div>
    <div class="H-padding-vertical-bottom-10"></div>
    <div class="H-border-vertical-both-after">

        <div class="H-flexbox-horizontal H-border-vertical-bottom-margin-left-10-after">
            <span class="H-vertical-middle H-padding-horizontal-left-10 H-theme-background-color-white H-font-size-16">&nbsp;&nbsp;&nbsp;&nbsp;旧密码：</span>
            <input id="oldPassword" type="text" class="H-textbox H-vertical-align-middle H-vertical-middle H-font-size-16 H-flex-item H-box-sizing-border-box H-border-none H-outline-none H-padding-12" placeholder="请输入原来的密码..." /><span class="H-icon H-vertical-middle H-padding-horizontal-right-10 H-theme-background-color-white"><i class="H-iconfont H-icon-warn H-font-size-18 H-vertical-middle H-theme-font-color-red"></i></span>
        </div>
        <div class="H-flexbox-horizontal H-border-vertical-bottom-margin-left-10-after">
            <span class="H-vertical-middle H-padding-horizontal-left-10 H-theme-background-color-white H-font-size-16">&nbsp;&nbsp;&nbsp;&nbsp;新密码：</span>
            <input id="newPassword" type="text" class="H-textbox H-vertical-align-middle H-vertical-middle H-font-size-16 H-flex-item H-box-sizing-border-box H-border-none H-outline-none H-padding-12" placeholder="请输入新的密码..." /><span class="H-icon H-vertical-middle H-padding-horizontal-right-10 H-theme-background-color-white"><i class="H-iconfont H-icon-warn H-font-size-18 H-vertical-middle H-theme-font-color-red"></i></span>
        </div>
		<div class="H-flexbox-horizontal H-border-vertical-bottom-margin-left-10-after">
		    <span class="H-vertical-middle H-padding-horizontal-left-10 H-theme-background-color-white H-font-size-16">重复密码：</span>
		    <input id="confirmPassword" type="text" class="H-textbox H-vertical-align-middle H-vertical-middle H-font-size-16 H-flex-item H-box-sizing-border-box H-border-none H-outline-none H-padding-12" placeholder="请再次输入新的密码..." /><span class="H-icon H-vertical-middle H-padding-horizontal-right-10 H-theme-background-color-white"><i class="H-iconfont H-icon-warn H-font-size-18 H-vertical-middle H-theme-font-color-red"></i></span>
		</div>
    </div>
    <div class="H-text-align-center H-margin-vertical-top-15 H-position-relative">
        <span onclick="updatePassword()" class="H-theme-font-color-red H-font-size-22 H-margin-vertical-bottom-15 H-display-block H-theme-background-color-white H-position-absolute H-padding-vertical-both-10" style="left:10px;right:10px;">修改密码</span>
    </div>

    <script src="../../script/H.js" type="text/javascript"></script>
    <script src="../../script/jquery-3.7.1.min.js" type="text/javascript"></script>
    <script src="../../api.js" type="text/javascript"></script>
    <script type="text/javascript">

        // /users/update/password

        function updatePassword() {
            var oldPassword = $('#oldPassword').val();
            var newPassword = $('#newPassword').val();
            var confirmPassword = $('#confirmPassword').val();
            if (oldPassword == '') {
                alert('请输入原密码');
                return false;
            }
            if (newPassword == '') {
                alert('请输入新密码');
                return false;
            }
            if (confirmPassword == '') {
                alert('请确认新密码');
                return false;
            }
            if (newPassword != confirmPassword) {
                alert('两次输入的密码不一致');
                return false;
            }
			
			var userId = localStorage.getItem("userId")
			
            $.ajax({
                url: baseServer +'user/update/password',
                type: 'POST',
				contentType:'application/json;charset=utf-8',
				dataType : "json", 
				data : JSON.stringify({
                    oldPassword: oldPassword,
                    newpassword: newPassword,
                    confirmPassword: confirmPassword,
					id:userId
                }),
                success: function(data) {
                    if (data.success) {
                        alert('密码修改成功，请重新登录');
						goBack();
                    } else {
                        alert(data.message);
                    }
                },
                error: function(xhr, type) {
                    alert('网络错误，请稍后再试');
                }
            });

        }


    </script>



</body>
</html>